package teehee.Manager;

import java.util.ArrayList;
import teehee.Action.SearchPageAction;
import teehee.DB.DB;
import teehee.DB.DBHistory;

/**
 * Manager class for Exercise History to access the database
 * @author Connie
 */
public class HistoryManager {
	
	////////// MOCKDB METHODS //////////
	
	/**
	 * Accesses database to find MockDB object's type
	 * @param entry MockDB object
	 * @return String wod or ex
	 */
	public static String getType( DB entry ) {
		return entry.getType();
	}

	/**
	 * Accesses database to find MockDB object's name and formats the String
	 * @param entry MockDB object
	 * @return name of the exercise/wod in proper format
	 */
	public static String getFormattedName( DB entry ) {
		return SearchPageAction.convertBack( entry.getName() );
	}
	
	/**
	 * Accesses database to find MockDB object's name
	 * @param entry MockDB object
	 * @return name of the exercise/wod
	 */
	public static String getName( DB entry ) {
		return entry.getName();
	}
	
	/**
	 * Accesses database to find MockDB object's exercise list
	 * @param entry MockDB object
	 * @return ArrayList containing exercises listed in the wod
	 */
	public static ArrayList<String> getExerciseList( DB entry ) {
		return entry.getExerciseList();
	}
	
	/**
	 * Accesses database to find MockDB object's description
	 * @param entry MockDB object
	 * @return description of wod/exercise
	 */
	public static String getDescription( DB entry ) {
		return SearchPageAction.convertBack( entry.getComments() );
	}
	
	////////// MOCKDBHISTORY METHODS //////////

	/**
	 * Accesses database to find MockDBHistory object's name
	 * @param entry MockDB object
	 * @return name of the exercise/wod
	 */
	public static String getName( DBHistory entry ) {
		return SearchPageAction.convertBack( entry.getName() );
	}	
	
	/**
	 * Accesses database to find MockDBhistory object's history (by date)
	 * @param entry MockDBHistory object
	 * @return ArrayList containing all past completions of a certain day
	 */
	public static ArrayList<DBHistory> getHistoryByDate( String date ) {
		return DBHistory.getHistoryByDate( date );
	}	
	
	/**
	 * Accesses database to find MockDBhistory object's history (by name)
	 * @param entry MockDBHistory object
	 * @return ArrayList containing all past completions of the wod/ex
	 */
	public ArrayList<DBHistory> getHistoryByName( String name, String type ) {
		return DBHistory.getHistoryByName( name, type );
	}
	
	/**
	 * Accesses database to find MockDBHistory object's exercise list
	 * @param entry MockDB object
	 * @return ArrayList containing exercises listed in the wod
	 */
	public static ArrayList<String> getExerciseList( DBHistory entry ) {
		return entry.getExerciseList();
	}
	
	/**
	 * Accesses database to find MockDBhistory object's date
	 * @param entry MockDBhistory object
	 * @return dates of completions for the wod/ex
	 */
	public static String getDate( DBHistory entry ) {
		String date = SearchPageAction.convertBack( entry.getDate() );
		String formattedDate = date.substring( 0,2 ) + '-' + date.substring(2,4) + '-'
				+ date.substring(4);
		
		return formattedDate;
	} 

	/**
	 * Accesses database to find MockDBhistory object's time
	 * @param entry MockDBhistory object
	 * @return time taken for the wod/ex
	 */
	public static String getTime( DBHistory entry ) {
		return SearchPageAction.convertBack( entry.getTime() );
	}
	
	/**
	 * Accesses database to find MockDBhistory object's time
	 * @param entry MockDBhistory object
	 * @return time taken for the wod/ex
	 */
	public static String getWeights( DBHistory entry ) {
		return SearchPageAction.convertBack( entry.getWeights() );
	}
	
	/**
	 * Accesses database to find MockDBhistory object's reps
	 * @param entry MockDBhistory object
	 * @return reps done for the wod/ex
	 */
	public static String getReps( DBHistory entry ) {
		return SearchPageAction.convertBack( entry.getReps() );
	}
	
	/**
	 * Accesses database to find MockDBhistory object's comments
	 * @param entry MockDBhistory object
	 * @return comments for the completion of the wod
	 */
	public static String getComments( DBHistory entry ) {
		return SearchPageAction.convertBack( entry.getComments() );
	}
}
